<template>
    <div>
        <button @click="incc">+</button>
        <button @click="decc">-</button>
        <button @click="cha">同步变化</button>
        <button @click="chatime">异步变化</button>


        <h1>
            {{$store.state.count}}
            {{$store.state.info}}
        </h1>
    </div>
</template>

<script>
    // @ is an alias to /src
    // import HelloWorld from '@/components/HelloWorld.vue'

    export default {
        name: 'home',
        components: {},
        methods: {
            incc() {
                this.$store.commit('inc', {
                    name: '小明',
                    age: '12',
                    like: '吃东西'
                })
            },
            decc() {
                this.$store.commit({
                    type: 'dec',
                    num: 10
                })
            },
            cha() {
                this.$store.commit('add')
            },
            chatime() {
                // 异步操作
                // this.$store.commit('chatime')

                // 回调完成
                /*this.$store.dispatch('achatime', {
                    msg: '参数',
                    success() {
                        console.log('完成');
                    }
                })*/

                // promise 完成
                this.$store.dispatch('achatime', '参数哦').then(() => {
                    console.log('完成了');
                })
            }
        }
    }
</script>
